package cn.smile.controller.basic;

import cn.smile.bean.dto.basic.MemberInfoDTO;
import cn.smile.bean.form.basic.member.MemberAddForm;
import cn.smile.bean.form.basic.member.MemberUpdateForm;
import cn.smile.bean.form.basic.member.QueryMemberForm;
import cn.smile.business.basic.IMemberService;
import cn.smile.commons.response.MyResult;
import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;

@RestController
@RequestMapping("api/member")
public class MemberController {

    @Resource
    private IMemberService service;

    @GetMapping(value = "checkNo")
    public MyResult<Boolean> checkNo(@RequestParam("memberNo") String memberNo, @RequestParam("id") String id) {
        return MyResult.OK(service.checkNo(memberNo, id));
    }

    @PostMapping(value = "add")
    public MyResult<Boolean> addInfo(@Valid @RequestBody MemberAddForm form) {
        return MyResult.OK(service.addInfo(form));
    }

    @PostMapping(value = "update")
    public MyResult<Boolean> updateInfo(@Valid @RequestBody MemberUpdateForm form) {
        return MyResult.OK(service.updateInfo(form));
    }

    @PostMapping(value = "getMemberPage")
    public MyResult<IPage<MemberInfoDTO>> getMemberPage(@RequestBody QueryMemberForm form) {
        return MyResult.OK(service.getMemberPage(form));
    }

    @GetMapping(value = "delMember")
    public MyResult<Boolean> delMember(@RequestParam("id") String id) {
        return MyResult.OK(service.delMember(id));
    }

    @GetMapping(value = "getMemberById")
    public MyResult<MemberInfoDTO> getMemberById(@RequestParam("id") String id) {
        return MyResult.OK(service.getMemberById(id));
    }

    @GetMapping(value = "getBaseMemberById")
    public MyResult<MemberInfoDTO> getBaseMemberById(@RequestParam("id") String id) {
        return MyResult.OK(service.getBaseMemberById(id));
    }
}
